package vcp.gui.forms;

import java.util.Observable;
import java.util.Observer;

import vcp.gui.components.VCPPanel;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import java.awt.Color;

import client.Message;

import com.toedter.calendar.JDateChooser;

import db.parking.beans.Subscriber;

import javax.swing.border.TitledBorder;

/**
 * Full Subscription Form 
 *
 */
public class SubscriptionFormFull extends VCPPanel implements Observer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField textCID; 
	public JTextField getCarNo_field() {
		return carNo_field;
	}
	public void setCarNo_field(JTextField carNo_field) {
		this.carNo_field = carNo_field;
	}
	public JLabel getLblSubscriptionStart() {
		return lblSubscriptionStart;
	}
	public void setLblSubscriptionStart(JLabel lblSubscriptionStart) {
		this.lblSubscriptionStart = lblSubscriptionStart;
	}
	public JLabel getCusID() {
		return cusID;
	}
	public void setCusID(JLabel cusID) {
		this.cusID = cusID;
	}
	public JLabel getCarNo() {
		return carNo;
	}
	public void setCarNo(JLabel carNo) {
		this.carNo = carNo;
	}
	public JDateChooser getDateChooser_start() {
		return dateChooser_start;
	}
	public void setDateChooser_start(JDateChooser dateChooser_start) {
		this.dateChooser_start = dateChooser_start;
	}
	private JButton btnSusbcribe;
	private JTextField carNo_field;
	private JLabel lblSubscriptionStart;
	private JLabel cusID;
	private JLabel carNo;
	private JDateChooser dateChooser_start;
	/**
	 * Create the panel.
	 */
	public SubscriptionFormFull() {
		setBorder(new TitledBorder(null, "Subscription", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setBackground(Color.WHITE);
		
		cusID = new JLabel("Customer ID");
		
		textCID = new JTextField();
		textCID.setColumns(10);
		
		btnSusbcribe = new JButton("Subscribe");
		btnSusbcribe.setActionCommand("full_subscription");
		
		carNo = new JLabel("Car Number");
		
		carNo_field = new JTextField();
		carNo_field.setColumns(10);
		
		lblSubscriptionStart = new JLabel("Subscription Start");
		
		dateChooser_start = new JDateChooser();
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblSubscriptionStart, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addComponent(carNo, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addComponent(cusID)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(textCID, GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
						.addComponent(carNo_field, GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
						.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
							.addComponent(dateChooser_start, GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
							.addGap(202)))
					.addContainerGap())
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap(241, Short.MAX_VALUE)
					.addComponent(btnSusbcribe)
					.addGap(120))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(30)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textCID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(cusID))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(carNo_field, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(carNo))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(dateChooser_start, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblSubscriptionStart))
					.addGap(37)
					.addComponent(btnSusbcribe)
					.addGap(122))
		);
		setLayout(groupLayout);

	}
	public JTextField getTextCID() {
		return textCID;
	}
	public void setTextCID(JTextField textCID) {
		this.textCID = textCID;
	}
	public JButton getBtnSusbcribe() {
		return btnSusbcribe;
	}
	public void setBtnSusbcribe(JButton btnSusbcribe) {
		this.btnSusbcribe = btnSusbcribe;
	}
	@Override
	public void update(Observable o, Object arg) {
		Message tempMsg = (Message)arg; 
		Subscriber s = (Subscriber) tempMsg.getObj();

		switch(tempMsg.getMsg())
		 {
		 	case "AddFullSubscriber":
				if(tempMsg.isStatus())
				{
					JOptionPane.showMessageDialog(null , "Your Subscription Has Been Created , ID "+ Integer.toString(s.getSubID()));
				}	
				else
				{
					JOptionPane.showMessageDialog(null,"Subscription has failed,Try Again Later..: " + tempMsg.getStatusMsg(),"DATABASE ERROR",JOptionPane.ERROR_MESSAGE);
				}
				break;
		 }
		
	}
}
